import java.util.Stack;

public class Test {




    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '('||ch == '['||ch == '{'){
                stack.push(ch);
            }else {
                if (stack.empty()){
                    return false;//说明右括号多
                }
                char ch2 = stack.peek();
                if(ch == ')'&&ch2 == '(' || ch == '}'&&ch2 == '{' || ch == ']'&&ch2 == '['){
                    stack.pop();
                }else {
                    return false;
                }
            }

        }
        if (!stack.empty()){
            return false;
        }
        return true;
    }

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (String x : tokens){
            if (!inOperation(x)){
                stack.push(Integer.parseInt(x));
            }else {
                int num2= stack.pop();
                int num1 = stack.pop();
                switch (x){
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }
        return stack.pop();
    }

    public boolean inOperation(String x ){
        if (x.equals("+")||x.equals("-")||x.equals("*")||x.equals("/")){
            return true;
        }
        return false;
    }


    public static void main4(String[] args) {
        MySingleList mySingleList = new MySingleList();

        //插入数据
        mySingleList.addLast(10);//尾插法
        mySingleList.addLast(20);//尾插法
        mySingleList.addLast(30);//尾插法
        mySingleList.addLast(40);//尾插法
        mySingleList.addLast(50);//尾插法
        mySingleList.display4(mySingleList.head);
    }
    public static void main3(String[] args) {
        MyLinkendList myLinkendList = new MyLinkendList();
        myLinkendList.addLast(2);
        myLinkendList.addLast(2);
        myLinkendList.addLast(3);
        myLinkendList.addLast(2);
        myLinkendList.addLast(5);
        myLinkendList.display();
        System.out.println("================");
        myLinkendList.addIndex(1,2);
        myLinkendList.display();
        System.out.println("================");
        myLinkendList.remove(1);
        myLinkendList.display();
        System.out.println("================");
        myLinkendList.removeAllkey(2);
        myLinkendList.display();
        System.out.println("================");
        myLinkendList.clear();
        myLinkendList.display();


    }
    public static void main2(String[] args) {
        MySingleList mySingleList = new MySingleList();

        //插入数据
        mySingleList.addLast(10);//尾插法
        mySingleList.addLast(20);//尾插法
        mySingleList.addLast(30);//尾插法
        mySingleList.addLast(40);//尾插法
        mySingleList.addLast(50);//尾插法
        mySingleList.addLast(60);//尾插法
        mySingleList.display();
        System.out.println("==========");
        MySingleList.ListNode ret = mySingleList.ReverseList();
        mySingleList.display(ret);
        System.out.println("==========");
        MySingleList.ListNode ret1 = mySingleList.middleNode();
        mySingleList.display(ret1);
    }



    public static void main1(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.createLink(); //生成一个单项链表
        //插入数据
        mySingleList.addLast(30);//尾插法
        mySingleList.addLast(30);//尾插法
        mySingleList.addLast(30);//尾插法
        mySingleList.addLast(30);//尾插法
        mySingleList.addLast(30);//尾插法
        mySingleList.addLast(30);//尾插法
        mySingleList.display();//遍历链表
        System.out.println(mySingleList.contains(12));//查找链表是否存在k的值
        System.out.println(mySingleList.size());//计数器
        System.out.println("==================");
        mySingleList.addFirst(12);//头插法
        mySingleList.display();//遍历链表
        System.out.println("==================");
        mySingleList.addLast(30);//尾插法
        mySingleList.display();
        System.out.println("==================");
        mySingleList.addIndex(0,22);
        mySingleList.display();
        System.out.println("==================");
        mySingleList.remove(22);
        mySingleList.display();
        System.out.println("==================");
        mySingleList.removeAllkey(12);
        mySingleList.display();
        System.out.println("========清空==========");
        mySingleList.clear();
        mySingleList.display();
    }
}
